package cn.gene.timeyan.ums.webapi.ums.service.impl;

import cn.gene.timeyan.pojo.article.model.Article;
import cn.gene.timeyan.pojo.ums.model.Collect;
import cn.gene.timeyan.ums.service.ICollectService;
import cn.gene.timeyan.ums.webapi.ums.mapper.CollectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * 收藏   服务实现类 *
 *
 * @author LWG
 * @date 2022/7/22 17:40
 * @since 1.0.0@gene.cn
 */
@Slf4j
@Service
public class CollectServiceImpl implements ICollectService {
    @Autowired
    private CollectMapper collectMapper;

    @Override
    public void addCollecton(Long userId, Long articleId) {
        Collect collect = new Collect();
        Article article = new Article();
        collect.setUserId(userId);
        collect.setArticleId(articleId);
        Long moduleId=collectMapper.selectModuleId(articleId);
        collect.setModuleId(moduleId);
        collect.setState("1");
        collect.setCollectTime(LocalDateTime.now());
        collectMapper.insertCollectUser(collect);
        collectMapper.addCollectCount(articleId);

    }

    @Override
    public void deleteCollection(Long userId, Long articleId) {
        collectMapper.deleteCollectUserId(userId, articleId);
        collectMapper.reduceCollectCount(articleId);
    }

    @Override
    public Integer getCollectionNum(Long articleId) {
        log.info("articleId{}",articleId);
        Integer collectionNum=collectMapper.selectCollections(articleId);
        return collectionNum;
    }

}
